package com.ashafa.fileutils;



import java.io.File;
import java.io.FileInputStream;

import org.apache.log4j.*;



public class FetchFile {
	
	private static final Logger logger = Logger.getLogger(FetchFile.class.getName()); 
	
	public static String getString(String cononicalPath, String exceptionString){
		try
		{
			FileInputStream fileStream = new FileInputStream(cononicalPath);
	 		byte[] b = new byte[fileStream.available ()];
	 		fileStream.read(b);
	 		fileStream.close ();
	 		return new String(b);
		} catch(Exception e) {
			logger.warn(e.getMessage());
			return exceptionString;
		}
	}
	
	public static String readFile(String filePath, String exceptionString){
 		
		File file = null;
		try
 		{
			file= new File(filePath);
	 		
	 		return getString(file.getCanonicalPath(), exceptionString);
	 		
	
 		} catch(Exception e) {
 			logger.warn(e.getMessage());
 			return exceptionString;
 		}
	
		
	}
	
	
	

}
